home *** CD-ROM | disk | FTP | other *** search
- /* Parse a Miami settings file and output a resolv.conf file. */
-
- #include <exec/types.h>
- #include <exec/libraries.h>
- #include <exec/execbase.h>
- #include <dos/stdio.h>
- #include <dos/dosextens.h>
- #include <libraries/iffparse.h>
-
- #define __NOLIBBASE__
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/iffparse.h>
-
- #define ID_MIAM MAKE_ID('M','I','A','M')
- #define ID_DBDN MAKE_ID('D','B','D','N')
- #define ID_DBDO MAKE_ID('D','B','D','O')
-
- LONG tinymain (VOID)
- {
- struct ExecBase *SysBase;
- struct DOSBase *DOSBase;
- struct Library *IFFParseBase;
-
- SysBase = * (struct ExecBase **) 4;
-
- if ((DOSBase = (struct DOSBase *) OpenLibrary ("dos.library", 33)))
- {
- if ((IFFParseBase = OpenLibrary ("iffparse.library", 33)))
- {
- struct IFFHandle *iffh;
- struct StoredProperty *sp;
-
- if ((iffh = AllocIFF ()))
- {
- /* Set up standard input as stream. */
- iffh->iff_Stream = Input ();
- InitIFFasDOS (iffh);
-
- if (0 == OpenIFF (iffh, IFFF_READ))
- {
- /* Tell the parser to extract these chunks. */
- PropChunk (iffh, ID_MIAM, ID_DBDN);
- PropChunk (iffh, ID_MIAM, ID_DBDO);
-
- /* Tell the parser to stop when it gets to the end of the data. */
- StopOnExit (iffh, ID_MIAM, ID_FORM);
-
- /* Parse the settings file. */
- ParseIFF (iffh, IFFPARSE_SCAN);
-
- /* Print list of DNS servers, if any. */
- if ((sp = FindProp (iffh, ID_MIAM, ID_DBDN)))
- {
- ULONG i;
- char *dnsServer = sp->sp_Data;
-
- for (i = 0; *dnsServer; i ++, dnsServer ++)
- {
- PutStr ("nameserver "); PutStr (dnsServer); WriteChar ('\n');
- while (*dnsServer)
- dnsServer ++;
- }
- }
-
- /* Print list of domains to search, if any. */
- if ((sp = FindProp (iffh, ID_MIAM, ID_DBDO)))
- {
- ULONG i;
- char *domain = sp->sp_Data;
-
- for (i = 0; *domain; i ++, domain ++)
- {
- if (i == 0)
- PutStr ("domain");
- WriteChar (' '); PutStr (domain);
- while (*domain)
- domain ++;
- }
- WriteChar ('\n');
- }
- CloseIFF (iffh);
- }
- FreeIFF (iffh);
- }
- CloseLibrary (IFFParseBase);
- }
- CloseLibrary ((struct Library *) DOSBase);
- }
- return (RETURN_OK);
- }